Your task this week is to make a program named "fizzbuzz". The rules
For extra points:
For extra points you need to make your code easily modifiable. I want to be able to:
However, I am a stupid robot that can only type 3 characters at a time. Therefore, to modify your code I cannot go inside it and change stuff by myself. I need you to guide my hand all the way. *(Hint you should use Pythons "input" Function).
In [3]:
for number in range(1,101): # remember, end point is exclusive
fizz = "fizz" if number % 2 == 0 else False
buzz = "buzz" if number % 5 == 0 else False
if fizz and buzz:
print(fizz + buzz)
elif fizz:
print(fizz)
elif buzz:
print(buzz)
else:
print(number)
In [1]:
msg_1 = input("please give me a string to replace 'fizz' with " )
msg_2 = input("please give me a string to replace 'buzz' with ")
game_length = int(input("we should go up to the number..."))
mod_1 = int(input("{} should be divisble by...".format(msg_1)))
mod_2 = int(input("{} should be divisible by...".format(msg_2)))
print("LET THE GAMES BEGIN!")
for number in range(1, game_length + 1):
rule_1 = msg_1 if number % int(mod_1) == 0 else False
rule_2 = msg_2 if number % int(mod_2) == 0 else False
if rule_1 and rule_2:
print(rule_1 + rule_2)
elif rule_1 and not rule_2:
print(rule_1)
elif rule_2 and not rule_1:
print(rule_2)
else:
print(number)
In [ ]: